package com.yearner.reviewplan.common.model;

import com.yearner.reviewplan.common.util.MyJdbcUtil;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

/**
 * @author pengyg
 * @since 2019/10/22
 */
@Repository
public abstract class BaseRepository {
    protected final MyJdbcUtil myJdbcUtil;
    protected JdbcTemplate jdbcTemplate;

    public BaseRepository(MyJdbcUtil myJdbcUtil) {
        this.jdbcTemplate = new JdbcTemplate(myJdbcUtil.getDataSource());
        this.myJdbcUtil = myJdbcUtil;
    }

    protected abstract RowMapper mapper();

    protected String getByOneParamSql(String table, String id) {
        return String.format("select * from %s where %s = ?", table, id);
    }

    protected String getOneAndOneSql(String table, String column1,String column2) {
        return String.format("select * from %s where %s = ? and %s=?", table, column1,column2);
    }
}
